package com.winchain.chainbill.serfee.rx;

import com.shell.bee.base.utils.StringUtil;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.basic.charge.po.ValRetBiz;
import com.winchain.chainbill.basic.charge.service.ValRetBizService;
import com.winchain.chainbill.tbill.base.po.TbDct;
import com.winchain.chainbill.tbill.biz.TBill;
import com.winchain.chainbill.tbill.biz.TBillEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TBillDctUpdateSerFeeSubscriber extends OnErrorNotImplementedSubscriber<TBillEvent<TbDct>> {
	@Autowired
	private ValRetBizService valRetBizService;

	public void onApplicationEvent(TBillEvent<TbDct> t) {
		String bizState = t.getStringValue("serFeeBizState");
		if (StringUtil.notEmpty(bizState)) {
			TbDct dct = (TbDct) t.getBill().getSource();
			ValRetBiz valRetBiz = this.valRetBizService.selectByBizId(dct.getDctId());
			if (valRetBiz != null) {
				valRetBiz.setState(bizState);
				this.valRetBizService.updateNotNull(valRetBiz);
			}
		}
	}
}
